1   /*
2    * Copyright (C) 2012 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.google.common.collect;
18  
19  import com.google.common.annotations.GwtCompatible;
20  import com.google.common.base.Function;
21  
22  import java.util.ListIterator;
23  
24  /**
25   * An iterator that transforms a backing list iterator; for internal use. This
26   * avoids the object overhead of constructing a {@link Function} for internal
27   * methods.
28   *
29   * @author Louis Wasserman
30   */
31  @GwtCompatible
32  abstract class TransformedListIterator<F, T> extends TransformedIterator<F, T>
33      implements ListIterator<T> {
34    TransformedListIterator(ListIterator<? extends F> backingIterator) {
35      super(backingIterator);
36    }
37  
38    private ListIterator<? extends F> backingIterator() {
39      return Iterators.cast(backingIterator);
40    }
41  
42    @Override
43    public final boolean hasPrevious() {
44      return backingIterator().hasPrevious();
45    }
46  
47    @Override
48    public final T previous() {
49      return transform(backingIterator().previous());
50    }
51  
52    @Override
53    public final int nextIndex() {
54      return backingIterator().nextIndex();
55    }
56  
57    @Override
58    public final int previousIndex() {
59      return backingIterator().previousIndex();
60    }
61  
62    @Override
63    public void set(T element) {
64      throw new UnsupportedOperationException();
65    }
66  
67    @Override
68    public void add(T element) {
69      throw new UnsupportedOperationException();
70    }
71  }